package com.example.geomanager;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MapLocationListener implements LocationListener {
	private MapView mapView;
	private Context context;
	private PointsTracer pointsTracer;
	
	public MapLocationListener(MapView mapView, Context context)
	{
		this.mapView = mapView;
		this.context = context;
		pointsTracer = new PointsTracer(mapView);
	}
	
	public void onLocationChanged(Location location)
	{
		// Called when a new location is found by the network location provider.
		Log.i(MainActivity.TAG, String.format("%f, %f\n", location.getLatitude(), location.getLongitude()));
		
		List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = context.getResources().getDrawable(R.drawable.ic_launcher);
        PinpointItemizedOverlay itemizedOverlay = new PinpointItemizedOverlay(drawable, context);
        
        GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6));
        OverlayItem overlayItem = new OverlayItem(point, "hello", "bla");
        
        itemizedOverlay.addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlay);
        
        pointsTracer.startTracing();
	}

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
}
